<template>
  <div class="home-new">
    <Panel :title="'人气推荐'" :subTitle="'人气爆款 不容错过'">
      <template #right>
        <XtxMore path="/"></XtxMore>
      </template>
      <div ref="target">
           <transition-group name="fade">
        <!-- 面板内容 -->
        <ul v-if="result.length" ref="pannel" class="goods-list">
          <li v-for="item in result" :key="item.id">
            <RouterLink to="/">
              <img v-lazy='item.picture' alt="" />
              <p class="name">{{ item.title }}</p>
              <p class="desc">{{ item.alt }}</p>
            </RouterLink>
          </li>
        </ul>
        <!-- 骨架 -->
        <Homeskeleton v-else />
      </transition-group>
      </div>
    </Panel>
  </div>
</template>

<script>
import { ref } from "vue";
import Panel from "./home-panel.vue";
import { findHot } from "@/api/home";
import { useLazyData } from "@/hooks/index";
import Homeskeleton from "./home-skeleton.vue";

export default {
  name: "homeNew",
  components: { Panel,Homeskeleton },
  setup(props) {
    // const list = ref([]);
    // findHot().then((res) => {
    //   list.value = res.result;
    // });
    const {result,target} = useLazyData(findHot)
    return { result, target };
  },
};
</script>
<style scoped lang='less'>
// 嵌套语法 & 父级类名
.fade {
  &-leave {
    &-active {
      position: absolute;
      width: 100%;
      transition: opacity 0.5s 0.2s;
      z-index: 1;
    }
    &-to {
      opacity: 0;
    }
  }
}

.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>

